package com.bops.dal.order.dao.impl;

import java.util.List;

import com.bops.dal.order.dao.OrderDAO;
import com.bops.dal.order.dataobject.OrderInfoDO;
import com.bops.dal.order.queryobject.OrderInfoQuery;
import com.yue.commons.db.ibatis.YueBaseSqlMapClientDaoSupport;

public class OrderDAOImpl  extends YueBaseSqlMapClientDaoSupport implements OrderDAO{

	private static final String NAME_SPACE = "ORDER_ORDER.";
	
	public Integer insert(OrderInfoDO orderDO) {
		return (Integer) getSqlMapClientTemplate().insert(NAME_SPACE + "insert", orderDO);
	}

	public boolean update(OrderInfoDO orderDO) {
		return getSqlMapClientTemplate().update(NAME_SPACE + "update", orderDO) > 0;
	}

	public OrderInfoDO getById(Integer id) {
		return (OrderInfoDO) getSqlMapClientTemplate().queryForObject(NAME_SPACE + "listById", id);
	}

    @SuppressWarnings("unchecked")
	public List<OrderInfoDO> listOrder(OrderInfoQuery query) {
    	if (query==null)
        {
            query = new OrderInfoQuery();
            query.setPageSize(Integer.MAX_VALUE);
        }
		return getSqlMapClientTemplate().queryForPagination(NAME_SPACE + "count_order", NAME_SPACE + "list_order", query);
	}

	public boolean delete(Integer id) {
		return getSqlMapClientTemplate().delete(NAME_SPACE + "delete", id) > 0;
	}

	public Integer maxOrderID() {
		return (Integer) getSqlMapClientTemplate().queryForObject(NAME_SPACE + "max_by_order");
	}


}
